import java.util
import scala.collection.mutable

// 创建样例类
case class UserInfo(name: String, location: String, startTime: Int, duration: Int)

object HomeWork3 {


  def main(args: Array[String]): Unit = {
    //创建用户，填充数据

    val userinfoList: List[UserInfo] = List(
      UserInfo("UserA", "LocationA", 9, 60),
      UserInfo("UserA", "LocationA", 4, 60),
      UserInfo("UserA", "LocationA", 8, 60),
      UserInfo("UserB", "LocationB", 9, 60),
      UserInfo("UserB", "LocationB", 10, 60)
    )

    //通过用户名和地点，组合成一个唯一键，来进行合并
    val userLocationMap: Map[String, List[UserInfo]] = userinfoList.groupBy(t => t.name + "," + t.location)

    //通过map的一些api进行对startTime的排序获取最小值和通过map的sum进行duration的求和
    val result = userLocationMap.map(x => {
      val array = x._1.split(",")
      UserInfo(array(0), array(1), x._2.minBy(x => x.startTime).startTime, x._2.map(x => x.duration).sum)
    })
    for(v<-result){
      println(v)
    }

  }

}
